From 6a2a2c9580d8974a1b98d023cb87a739d6b5fbe0 Mon Sep 17 00:00:00 2001 From: Alex Crichton Date: Tue, 5 Aug 2014 23:34:55 -0700 Subject: [PATCH] Ensure env vars are set for cargo-doc This erroneously used util::process instead of the custom process function in the cargo_rustc module. --- src/cargo/core/manifest.rs | 47 ++++++++++++++++++---------- src/cargo/ops/cargo_rustc/context.rs | 3 +- src/cargo/ops/cargo_rustc/mod.rs | 2 +- src/cargo/util/toml.rs | 5 ++- tests/support/paths.rs | 2 +- tests/test_cargo_compile_plugins.rs | 16 ++++++++-- 6 files changed, 52 insertions(+), 23 deletions(-) diff --git a/src/cargo/core/manifest.rs b/src/cargo/core/manifest.rs index e4249ca9c..f31d322c9 100644 --- a/src/cargo/core/manifest.rs +++ b/src/cargo/core/manifest.rs @@ -109,11 +109,24 @@ pub struct Profile { opt_level: uint, debug: bool, test: bool, + doc: bool, dest: Option, plugin: bool, } impl Profile { + fn default() -> Profile { + Profile { + env: String::new(), + opt_level: 0, + debug: false, + test: false, + doc: false, + dest: None, + plugin: false, + } + } + pub fn default_dev() -> Profile { Profile { env: "compile".to_string(), // run in the default environment only @@ -122,50 +135,45 @@ impl Profile { test: false, // whether or not to pass --test dest: None, plugin: false, + doc: false, } } pub fn default_test() -> Profile { Profile { - env: "test".to_string(), // run in the default environment only - opt_level: 0, + env: "test".to_string(), debug: true, - test: true, // whether or not to pass --test + test: true, dest: Some("test".to_string()), - plugin: false, + .. Profile::default() } } pub fn default_bench() -> Profile { Profile { - env: "bench".to_string(), // run in the default environment only + env: "bench".to_string(), opt_level: 3, - debug: false, - test: true, // whether or not to pass --test + test: true, dest: Some("bench".to_string()), - plugin: false, + .. Profile::default() } } pub fn default_release() -> Profile { Profile { - env: "release".to_string(), // run in the default environment only + env: "release".to_string(), opt_level: 3, - debug: false, - test: false, // whether or not to pass --test dest: Some("release".to_string()), - plugin: false, + .. Profile::default() } } pub fn default_doc() -> Profile { Profile { env: "doc".to_string(), - opt_level: 0, - debug: false, - test: false, dest: Some("doc-build".to_string()), - plugin: false, + doc: true, + .. Profile::default() } } @@ -174,7 +182,7 @@ impl Profile { } pub fn is_doc(&self) -> bool { - self.env.as_slice() == "doc" + self.doc } pub fn is_test(&self) -> bool { @@ -216,6 +224,11 @@ impl Profile { self } + pub fn doc(mut self, doc: bool) -> Profile { + self.doc = doc; + self + } + pub fn plugin(mut self, plugin: bool) -> Profile { self.plugin = plugin; self diff --git a/src/cargo/ops/cargo_rustc/context.rs b/src/cargo/ops/cargo_rustc/context.rs index 4f86a70b5..95e507075 100644 --- a/src/cargo/ops/cargo_rustc/context.rs +++ b/src/cargo/ops/cargo_rustc/context.rs @@ -227,7 +227,8 @@ impl<'a, 'b> Context<'a, 'b> { // doc-all == document everything, so look for doc targets and // compile targets in dependencies "doc-all" => target.get_profile().is_compile() || - target.get_profile().is_doc(), + (target.get_profile().get_env() == "doc" && + target.get_profile().is_doc()), _ => target.get_profile().get_env() == self.env, } } diff --git a/src/cargo/ops/cargo_rustc/mod.rs b/src/cargo/ops/cargo_rustc/mod.rs index 91c23b77b..da46d85ce 100644 --- a/src/cargo/ops/cargo_rustc/mod.rs +++ b/src/cargo/ops/cargo_rustc/mod.rs @@ -240,7 +240,7 @@ fn rustdoc(package: &Package, target: &Target, cx: &mut Context) -> Work { let kind = KindTarget; let pkg_root = package.get_root(); let cx_root = cx.layout(kind).proxy().dest().dir_path().join("doc"); - let rustdoc = util::process("rustdoc").cwd(pkg_root.clone()); + let rustdoc = process("rustdoc", package, cx).cwd(pkg_root.clone()); let rustdoc = rustdoc.arg(target.get_src_path()) .arg("-o").arg(cx_root) .arg("--crate-name").arg(target.get_name()); diff --git a/src/cargo/util/toml.rs b/src/cargo/util/toml.rs index 22196e670..efce15718 100644 --- a/src/cargo/util/toml.rs +++ b/src/cargo/util/toml.rs @@ -513,7 +513,10 @@ fn normalize(libs: &[TomlLibTarget], } match dep { - Needed => ret.push(Profile::default_test().test(false)), + Needed => { + ret.push(Profile::default_test().test(false)); + ret.push(Profile::default_doc().doc(false)); + } _ => {} } diff --git a/tests/support/paths.rs b/tests/support/paths.rs index 51180e38d..b8fd197c5 100644 --- a/tests/support/paths.rs +++ b/tests/support/paths.rs @@ -75,7 +75,7 @@ impl PathExt for Path { let stat = try!(path.stat()); let hour = 1000 * 3600; - let mut newtime = stat.modified - hour; + let newtime = stat.modified - hour; fs::change_file_times(path, newtime, newtime) } } diff --git a/tests/test_cargo_compile_plugins.rs b/tests/test_cargo_compile_plugins.rs index 80e64088b..1b7f7431c 100644 --- a/tests/test_cargo_compile_plugins.rs +++ b/tests/test_cargo_compile_plugins.rs @@ -1,4 +1,4 @@ -use support::{project, execs}; +use support::{project, execs, cargo_dir}; use hamcrest::assert_that; fn setup() { @@ -12,14 +12,24 @@ test!(plugin_to_the_max { version = "0.0.1" authors = [] + [[lib]] + name = "foo_lib" + [dependencies.bar] path = "../bar" "#) .file("src/main.rs", r#" #![feature(phase)] #[phase(plugin)] extern crate bar; + extern crate foo_lib; - fn main() {} + fn main() { foo_lib::foo(); } + "#) + .file("src/foo_lib.rs", r#" + #![feature(phase)] + #[phase(plugin)] extern crate bar; + + pub fn foo() {} "#); let bar = project("bar") .file("Cargo.toml", r#" @@ -65,4 +75,6 @@ test!(plugin_to_the_max { assert_that(foo.cargo_process("cargo-build"), execs().with_status(0)); + assert_that(foo.process(cargo_dir().join("cargo-doc")), + execs().with_status(0)); }) -- 2.30.2